package com.test5;

import java.io.Serializable;
import java.util.Objects;

public class Students implements Serializable, Comparable<Students>{
    private static final long serialVersionUID = 120L;
    private String name;
    private transient int age;

    public static String code = "200";
    public Students(){

    }
    @Override
    public String toString() {
        return "Students{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    public Students(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Students students = (Students) o;
//        return age == students.age && Objects.equals(name, students.name);
        //重写
        //判断是不是同一个对象
        if (this == o){
            return true;
        }
        //判断是否空
        if (o == null){
            return false;
        }
        //判断是否是Students类型
        if (o instanceof Students){
            Students students = (Students) o;
            //比较属性
            if (this.name.equals(students.getName())&&this.age == students.age){
                return true;
            }
        }
        //不满足
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Students o) {
        //这里定义根据年龄大小来比较
        int n2 = this.age-o.getAge();
        return n2;
    }
}
